/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.fyx.secure.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author xljan
 */
@Entity
@Table(name = "secure_role")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "SecureRole.findAll", query = "SELECT s FROM SecureRole s"),
    @NamedQuery(name = "SecureRole.findByCode", query = "SELECT s FROM SecureRole s WHERE s.code = :code")})
public class SecureRole implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "code")
    private String code;
    @Lob
    @Size(max = 65535)
    @Column(name = "title")
    private String title;
    @Lob
    @Size(max = 65535)
    @Column(name = "description")
    private String description;
    @Lob
    @Size(max = 65535)
    @Column(name = "category")
    private String category;
    @ManyToMany(mappedBy = "secureRoleCollection")
    private Collection<SecureGroup> secureGroupCollection;

    public SecureRole() {
    }

    public SecureRole(String code) {
        this.code = code;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    @XmlTransient
    public Collection<SecureGroup> getSecureGroupCollection() {
        return secureGroupCollection;
    }

    public void setSecureGroupCollection(Collection<SecureGroup> secureGroupCollection) {
        this.secureGroupCollection = secureGroupCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (code != null ? code.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SecureRole)) {
            return false;
        }
        SecureRole other = (SecureRole) object;
        if ((this.code == null && other.code != null) || (this.code != null && !this.code.equals(other.code))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.fyx.secure.entity.SecureRole[ code=" + code + " ]";
    }
    
}
